Conditions | 18 |
Paths | 5184 |
Total Lines | 231 |
Lines | 0 |
Ratio | 0 % |
Changes | 0 |
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
Complex classes like $(document).ready often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes.
Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.
1 | var filter_item_width; |
||
156 | $window.load(function() { |
||
157 | // The sorter for the portfolio. |
||
158 | var has_filter = $('#filterNav'); |
||
159 | if('undefined' !== has_filter){ |
||
160 | $('#main').imagesLoaded( function(){ |
||
161 | lsxProjectThumbInit(); |
||
162 | lsxProjectFilterInit(); |
||
163 | |||
164 | jQuery('#main').css('opacity', '1' ); |
||
165 | }); |
||
166 | } |
||
167 | |||
168 | //Portfolio Hover Class |
||
169 | if(lsx_params.is_portfolio){ |
||
170 | $('.portfolio-content-wrapper').hover(function() { |
||
171 | $(this).addClass('active'); |
||
172 | }, function() { |
||
173 | $(this).removeClass('active'); |
||
174 | }); |
||
175 | } |
||
176 | |||
177 | $('.masonry > article').hover(function() { |
||
178 | $(this).addClass('active'); |
||
179 | }, function() { |
||
180 | $(this).removeClass('active'); |
||
181 | }); |
||
182 | |||
183 | // Bootstrat Menu |
||
184 | |||
185 | if (1199 < windowWidth) { |
||
186 | $('.navbar-nav li.dropdown a').each(function() { |
||
187 | $(this).removeClass('dropdown-toggle'); |
||
188 | $(this).removeAttr('data-toggle'); |
||
189 | }); |
||
190 | } |
||
191 | |||
192 | $('.dropdown').on('show.bs.dropdown', function() { |
||
193 | if (1200 > windowWidth) { |
||
194 | $(this).siblings('.open').removeClass('open').find('a.dropdown-toggle').attr('data-toggle', 'dropdown'); |
||
195 | $(this).find('a.dropdown-toggle').removeAttr('data-toggle'); |
||
196 | } |
||
197 | }); |
||
198 | |||
199 | $window.resize(function() { |
||
200 | if (1199 < windowWidth) { |
||
201 | $('.navbar-nav li.dropdown a').each(function() { |
||
202 | $(this).removeClass('dropdown-toggle'); |
||
203 | $(this).removeAttr('data-toggle'); |
||
204 | }); |
||
205 | } else { |
||
206 | $('.navbar-nav li.dropdown a').each(function() { |
||
207 | $(this).addClass('dropdown-toggle'); |
||
208 | $(this).attr('data-toggle','dropdown'); |
||
209 | }); |
||
210 | } |
||
211 | }); |
||
212 | |||
213 | // Grandchild Menu |
||
214 | |||
215 | var fixDropdownPosition = function() { |
||
216 | $('.navbar-nav > .menu-item:last-child').each(function() { |
||
217 | if ($(this).hasClass('menu-item-has-children')) { |
||
218 | var $firstMenuItem = $(this), |
||
219 | $dropdown = $firstMenuItem.children('.dropdown-menu'), |
||
220 | $dropdownItem = $dropdown.children('.menu-item-has-children'), |
||
221 | dropdownWidth, |
||
222 | firstMenuItemRight; |
||
223 | |||
224 | //if ($dropdownItem.length > 0) { |
||
225 | dropdownWidth = $dropdown.outerWidth(), |
||
226 | firstMenuItemRight = (windowWidth - ($firstMenuItem.offset().left + $firstMenuItem.outerWidth())); |
||
227 | |||
228 | if (firstMenuItemRight < dropdownWidth) { |
||
229 | $dropdown.addClass('pull-right'); |
||
230 | $dropdownItem.addClass('dropdown-menu-left'); |
||
231 | } |
||
232 | //} |
||
233 | } |
||
234 | }); |
||
235 | }; |
||
236 | |||
237 | if (1199 < windowWidth) { |
||
238 | fixDropdownPosition(); |
||
239 | } else { |
||
240 | $('.dropdown .dropdown > a').on("click", function(e) { |
||
241 | if (!$(this).hasClass('open')) { |
||
242 | $(this).addClass('open'); |
||
243 | $(this).next('.dropdown-menu').toggle(); |
||
244 | e.stopPropagation(); |
||
245 | e.preventDefault(); |
||
246 | } |
||
247 | }); |
||
248 | } |
||
249 | |||
250 | // Search menu (in mobile) |
||
251 | |||
252 | jQuery(document).on('click', 'header.banner #searchform button.search-submit', function(e) { |
||
253 | if (1200 > windowWidth) { |
||
254 | e.preventDefault(); |
||
255 | var form = jQuery(this).closest('form'); |
||
256 | |||
257 | if (form.hasClass('hover')) { |
||
258 | form.submit(); |
||
259 | } else { |
||
260 | form.addClass('hover'); |
||
261 | form.find('.search-field').focus(); |
||
262 | } |
||
263 | } |
||
264 | }); |
||
265 | |||
266 | jQuery(document).on('blur', 'header.banner #searchform .search-field', function(e) { |
||
267 | if (1200 > windowWidth) { |
||
268 | var form = jQuery(this).closest('form'); |
||
269 | form.removeClass('hover'); |
||
270 | } |
||
271 | }); |
||
272 | |||
273 | // Parallax Effect on Banners |
||
274 | |||
275 | var $banner, |
||
276 | $bannerImage, |
||
277 | $bannerContainer, |
||
278 | bannerHeight, |
||
279 | bannerContainerBaseSize, |
||
280 | bannerParallax = function() { |
||
281 | if ($window.scrollTop() <= windowHeight) { |
||
282 | var scrolled = $window.scrollTop() / windowHeight * 100, |
||
283 | paddingTop = (4 * scrolled), |
||
284 | base = -130, |
||
285 | top = base + (3 * scrolled), |
||
286 | bottom = base - (3 * scrolled), |
||
287 | breakpoint = bannerContainerBaseSize + paddingTop; |
||
288 | |||
289 | $bannerImage.css('top', top + 'px'); |
||
290 | $bannerImage.css('bottom', bottom + 'px'); |
||
291 | |||
292 | if (breakpoint < bannerHeight) { |
||
293 | $bannerContainer.css('padding-top', paddingTop + 'px'); |
||
294 | } |
||
295 | } |
||
296 | } |
||
297 | |||
298 | if (991 < windowWidth) { |
||
299 | $banner = $('.page-banner:not(.gmap-banner)'); |
||
300 | |||
301 | if ($banner.length > 0) { |
||
302 | $bannerImage = $banner.children('.page-banner-image'); |
||
303 | $bannerContainer = $banner.children('.container'); |
||
304 | bannerHeight = $banner.height(); |
||
305 | bannerContainerBaseSize = $bannerContainer.height() + |
||
306 | parseInt(($bannerContainer.css('margin-top')).replace('px', '')) + |
||
307 | parseInt(($bannerContainer.css('margin-bottom')).replace('px', '')) + |
||
308 | parseInt(($bannerContainer.css('padding-bottom')).replace('px', '')); |
||
309 | bannerParallax(); |
||
310 | |||
311 | $window.resize(function() { |
||
312 | bannerHeight = $banner.height(); |
||
313 | bannerContainerBaseSize = $bannerContainer.height() + |
||
314 | parseInt(($bannerContainer.css('margin-top')).replace('px', '')) + |
||
315 | parseInt(($bannerContainer.css('margin-bottom')).replace('px', '')) + |
||
316 | parseInt(($bannerContainer.css('padding-bottom')).replace('px', '')); |
||
317 | }); |
||
318 | |||
319 | $window.scroll(function(){ |
||
320 | bannerParallax(); |
||
321 | }); |
||
322 | } |
||
323 | } |
||
324 | |||
325 | // Comments anchor |
||
326 | |||
327 | if (document.location.hash == '#comments') { |
||
328 | var margin = jQuery('body').hasClass('top-menu-fixed') ? jQuery('header.banner').height() : 0; |
||
329 | margin += jQuery('body').hasClass('admin-bar') ? jQuery('#wpadminbar').height() : 0; |
||
330 | |||
331 | jQuery('html, body').animate({ |
||
332 | scrollTop: jQuery('.comments-link').offset().top - margin |
||
333 | }, 500, function() { |
||
334 | jQuery('.comments-link').trigger('click'); |
||
335 | }); |
||
336 | } |
||
337 | |||
338 | if ((new RegExp("#comment-", "gi")).test(document.location.hash)) { |
||
339 | var margin = jQuery('body').hasClass('top-menu-fixed') ? jQuery('header.banner').height() : 0; |
||
340 | margin += jQuery('body').hasClass('admin-bar') ? jQuery('#wpadminbar').height() : 0; |
||
341 | |||
342 | jQuery('html, body').animate({ |
||
343 | scrollTop: jQuery('.comments-link').offset().top - margin |
||
344 | }, 500, function() { |
||
345 | jQuery('.comments-link').trigger('click'); |
||
346 | |||
347 | jQuery('html, body').animate({ |
||
348 | scrollTop: jQuery(document.location.hash).offset().top - margin |
||
349 | }, 500); |
||
350 | }); |
||
351 | } |
||
352 | |||
353 | // Sensei breadcrumb |
||
354 | if ($('body').hasClass('sensei')) { |
||
355 | if ($('header.archive-header').length > 0) { |
||
356 | $('.woocommerce-breadcrumb').insertAfter('.archive-header'); |
||
357 | |||
358 | if ($('.woocommerce-breadcrumb').length > 1) { |
||
359 | $('.woocommerce-breadcrumb').slice(1).remove(); |
||
360 | } |
||
361 | } |
||
362 | } |
||
363 | |||
364 | //Lazy Load //Envira Gallery FIX |
||
365 | var enviraIsotopUpdateLayout = function() { |
||
366 | jQuery('.envira-gallery-wrap').each(function() { |
||
367 | var id = jQuery(this).attr('id'); |
||
368 | id = id.replace('envira-gallery-wrap-', ''); |
||
369 | |||
370 | if (typeof envira_isotopes[id] == 'object') { |
||
371 | envira_isotopes[id].enviratope('layout'); |
||
372 | } |
||
373 | }); |
||
374 | }; |
||
375 | |||
376 | if (jQuery('.lazyload, .lazyloaded').length > 0) { |
||
377 | if (typeof envira_isotopes == 'object') { |
||
378 | $window.scroll(function(){ |
||
379 | enviraIsotopUpdateLayout(); |
||
380 | }); |
||
381 | } |
||
382 | } |
||
383 | |||
384 | //Final load - LAST CODE TO EXECUTE |
||
385 | $('body.preloader-content-enable').addClass('html-loaded'); |
||
386 | }); |
||
387 | }); |
||
445 | } |
The sequence or comma operator allows the inclusion of multiple expressions where only is permitted. The result of the sequence is the value of the last expression.
This operator is most often used in
for
statements.Used in another places it can make code hard to read, especially when people do not realize it even exists as a seperate operator.
This check looks for usage of the sequence operator in locations where it is not necessary and could be replaced by a series of expressions or statements.
could just as well be written as:
To learn more about the sequence operator, please refer to the MDN.